package com.fintech.third.utils;

import java.security.MessageDigest;

public class MD5Util {  
	
	public static String getMD5(String str) {
		MessageDigest md5;
		byte[] md5Byte=null;
		try {
			md5 = MessageDigest.getInstance("MD5");
			byte[] messageByte = str.getBytes("UTF-8");
			md5Byte = md5.digest(messageByte);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bytesToHex(md5Byte);
	}

	public static String bytesToHex(byte[] bytes) {
		StringBuffer hexStr = new StringBuffer();
		int num;
		for (int i = 0; i < bytes.length; i++) {
			num = bytes[i];
			if (num < 0) {
				num += 256;
			}
			if (num < 16) {
				hexStr.append("0");
			}
			hexStr.append(Integer.toHexString(num));
		}
		return hexStr.toString();
	}
	
}  